package com.eduction.modules.system.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.eduction.common.dbutil.DbHelper;
import com.eduction.common.dbutil.page.Page;
import com.eduction.modules.system.entity.Group;


@Repository
public class SiteInspectionGroupRepository {

	@Autowired
	private SiteInspectionGroupDao siteInspectionGroupDao;

	@Autowired
	private DbHelper dbHelper;
	/**
	 * 添加专家组
	 */
	public void saveGroup(Group group){
		this.siteInspectionGroupDao.save(group);
	}
	
	/**
	 * 查询单个专家组
	 */
	public Group selectGroupById(String id) throws SQLException{
		String sql = "select * from t_group where p_id = ?";
		return this.dbHelper.getBean(sql, Group.class, id);
	}
	
	/**
	 * 分页查询专家组
	 */
	public Page<Group> selectGroupByPage(Map<String,String> map,int type) throws SQLException{
		StringBuilder sql = new StringBuilder("SELECT s_name as s_name,s_state as s_state,p_id as pid,s_create_time  from t_group as t where s_type = "+type+" ") ;
		if(StringUtils.isNotBlank(map.get("name"))){
			sql.append(" and t.s_name like '%"+map.get("name").trim()+"%'");
		}
		return dbHelper.getPage(sql.toString(), Group.class, Integer.valueOf(map.get("pageNumber")), Integer.valueOf(map.get("pageSize")));
	}
	
	

}
